package com.ymatou.iapi.sellerproduct.testcase;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.json.JSONArray;
import org.json.JSONObject;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.livemanage.service.CreateLiveCall;
import com.ymatou.iapi.sellerproduct.service.AddProductInLivesCall;
import com.ymatou.iapi.sellerproduct.service.AttachProductToLivesCall;
import com.ymatou.iapi.sellerproduct.service.ChangeNewProductInfoCall;
import com.ymatou.iapi.sellerproduct.service.RemoveProductFromLiveCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.LiveCallService;
import com.ymttest.business.service.NewJavaMongoCheckService;
import com.ymttest.business.service.SellerProductCallService;
import com.ymttest.database.mongo.LiveProductInfoWapper;
import com.ymttest.database.mongo.LiveProductModelWapper;
import com.ymttest.database.mongo.YmtMongoDriverFactroy;
import com.ymttest.database.mongo.jproduct.LiveProductsWapper;
import com.ymttest.database.mongo.jproduct.ProductTimeStampBean;
import com.ymttest.database.mongo.jproduct.ProductTimeStampWapper;
import com.ymttest.database.sqlwapper.AttachProductToLivesWapper;
import com.ymttest.database.sqlwapper.YmtCatalogsIWapper;
import com.ymttest.database.sqlwapper.YmtProductsInLiveWapper;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.JsonBeanHelper;
import com.ymttest.utils.MapUtil;
import com.ymttest.utils.YMTDateUtil;

/**
 * 现货商品加入直播 FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_AttachProductToLives {
	private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
	private static SimpleDateFormat sdfForName = new SimpleDateFormat("MM-dd HH:mm:ss");
	public static SimpleDateFormat liveSDF = YMTDateUtil.getYMDHMSFormat();
	private static AttachProductToLivesCall attachproducttolivesCall;
	private static AddProductInLivesCall addProductInLivesCall = new AddProductInLivesCall();
	private static Integer sellerId = Integer.valueOf(EnvSetup.getData("productsellerid"));
	private static String sellerName = EnvSetup.getData("productsellername");
	private static Integer sellerId2 = Integer.valueOf(EnvSetup.getData("productsellerid2"));
	private static String sellerName2 = EnvSetup.getData("productsellername2");

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("现货商品加入直播");
	}

	@Before
	public void caseUp() {
		attachproducttolivesCall = new AttachProductToLivesCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(attachproducttolivesCall.getOpurl());
	}

	public static String chackreturncode(JSONObject dataStr) throws Exception {
		try {
			// 返回报文断言
			Logger.verifyNotNull(dataStr, "返回报文非空");
			// 断言"Code":200
			String code = dataStr.getString("Code");
			Logger.verifyIsContains(code, 200, "\"Code\":200");
			// 断言"Msg":""
			String msg = dataStr.getString("Msg");
			Logger.verifyIsNull(msg, "Msg等于空");
			// 断言"Trace":""
			String Trace = dataStr.getString("Trace");
			Logger.verifyIsNull(Trace, "Trace等于空");

		} catch (Exception e) {
			e.printStackTrace();
		}
		return "";
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_AttachProductToLives_001() {
		Logger.start(true, "现货加入直播(直播已开始)");
		try {
			// 创建直播
			JSONObject Live = LiveCallService.createLiveInProgress(sellerName, sellerId);
			Integer activityId1 = Live.getJSONObject("Data").getInt("ActivityId");

			// 发布商品
			Map<String, Object> map = new HashMap<String, Object>();

			// 销售状态 等于1 为 开始销售 销售状态等于0 为 未开始
			BigDecimal Price = new BigDecimal("100.00");
			BigDecimal VipPrice = new BigDecimal("10.00");
			BigDecimal NewCustomerPrice = new BigDecimal("10.00");
			String PictureUrl1 = "http://pc1.img.ymatou.com/G01/shangou/M00/2A/17/rBBlD1eqnq-AEvUHAANhqAY9_CQ839_n_w_o.jpg";
			map.put("Product->Catalogs[0]->Price", Price);
			map.put("Product->Catalogs[0]->VipPrice", VipPrice);
			map.put("Product->Catalogs[0]->NewCustomerPrice", NewCustomerPrice);
			map.put("Product->Catalogs[0]->PictureUrl1", PictureUrl1);
			JSONObject Product = SellerProductCallService.addNewProductOnSale(sellerId, sellerName, map);
			String ProductID1 = Product.getJSONObject("Data").getString("ProductID");

			// 直接加入商品 组装报文
			List<Integer> list = new ArrayList<>();
			list.add(activityId1);
			Map<String, Object> maplist = new HashMap<String, Object>();
			maplist.put("SellerId", sellerId);
			maplist.put("LiveIdList", new JSONArray(list));
			maplist.put("ProductId", ProductID1);

			// call 加入直播接口
			JSONObject dataStr = attachproducttolivesCall.callAndGetReturnData(maplist);
			// 报文断言
			chackreturncode(dataStr);

			YMTDateUtil.waitTime(1);

			// 业务层数据断言
			Map sqlm = new HashMap();
			sqlm.put("iActivityId", activityId1);
			sqlm.put("sProductId", ProductID1);
			AttachProductToLivesWapper attachProductToLivesWapper = new AttachProductToLivesWapper();
			List<Map> rm = attachProductToLivesWapper.selectAttachProductToLives(sqlm);
			if (rm.size() == 0) {
				Logger.debug("SQL没有存入直播信息");
			}
			String sProductIdbysql = (String) rm.get(0).get("sProductId");
			int iUserIdbysql = (int) rm.get(0).get("iUserId");
			int iActivityIdbysql = (int) rm.get(0).get("iActivityId");

			YMTDateUtil.waitTime(1);

			// 判断写入的字段正确
			Logger.verifyEquals(activityId1, iActivityIdbysql, "sql对比直播id");
			Logger.verifyEquals(ProductID1, sProductIdbysql, "sql对比商品id");
			Logger.verifyEquals(sellerId, iUserIdbysql, "sql对比用户id");

			if (YmtMongoDriverFactroy.isOldMongoCheck()) {
				// Mongo 老库检查 LiveProductInfo & LiveBasicInfo
				addProductInLivesCall.checkLiveProductInfo(Live, Product, activityId1, ProductID1);
				addProductInLivesCall.checkLiveBasicInfo(Live, Product, activityId1);

			}

			if (YmtMongoDriverFactroy.isNewMongoCheck()) {
				// Mongo 新库检查 LiveProductModel & LiveModel
				addProductInLivesCall.checkLiveProductModel(Live, Product, activityId1, ProductID1);
				addProductInLivesCall.checkLiveModel(Live, Product, activityId1);
			}

			if (YmtMongoDriverFactroy.isNewJavaMgoCheck()) {
				Logger.verifyEquals(1, new LiveProductsWapper().getCountByProductId(ProductID1),
						"Mongo-LiveProducts 检查直播商品记录个数");
				NewJavaMongoCheckService.checkProductMgoSyncBySQL_NewJavaMgo(ProductID1);
			}

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_AttachProductToLives_002() {
		Logger.start(true, "现货加入直播(商品为：发布不上架，直播为：未开始)");
		try {

			// 创建直播
			JSONObject Live = LiveCallService.createLiveNotInEffect(sellerName, sellerId);
			Integer activityId = Live.getJSONObject("Data").getInt("ActivityId");
			// 发布商品
			Map<String, Object> map = new HashMap<String, Object>();
			// 销售状态 等于1 为 开始销售 销售状态等于0 为 未开始
			BigDecimal Price = new BigDecimal("100.00");
			BigDecimal VipPrice = new BigDecimal("10.00");
			BigDecimal NewCustomerPrice = new BigDecimal("10.00");
			String PictureUrl1 = "http://pc1.img.ymatou.com/G01/shangou/M00/2A/17/rBBlD1eqnq-AEvUHAANhqAY9_CQ839_n_w_o.jpg";
			map.put("Product->Catalogs[0]->Price", Price);
			map.put("Product->Catalogs[0]->VipPrice", VipPrice);
			map.put("Product->Catalogs[0]->NewCustomerPrice", NewCustomerPrice);
			map.put("Product->Catalogs[0]->PictureUrl1", PictureUrl1);
			JSONObject Product = SellerProductCallService.addNewProductNotOnSale(sellerId, sellerName, map);
			String ProductID = Product.getJSONObject("Data").getString("ProductID");

			int activityId1 = activityId;
			String ProductID1 = ProductID;
			List<Integer> list = new ArrayList<>();
			list.add(activityId1);

			Map<String, Object> maplist = new HashMap<String, Object>();
			maplist.put("SellerId", sellerId);
			maplist.put("LiveIdList", new JSONArray(list));
			maplist.put("ProductId", ProductID1);

			// call 加入直播接口
			JSONObject dataStr = attachproducttolivesCall.callAndGetReturnData(maplist);
			// 报文断言
			chackreturncode(dataStr);

			// 业务层数据断言
			Map sqlm = new HashMap();
			sqlm.put("iActivityId", activityId1);
			sqlm.put("sProductId", ProductID1);
			AttachProductToLivesWapper attachProductToLivesWapper = new AttachProductToLivesWapper();
			List<Map> rm = attachProductToLivesWapper.selectAttachProductToLives(sqlm);
			if (rm.size() == 0) {
				return;
			}
			String sProductIdbysql = (String) rm.get(0).get("sProductId");
			int iUserIdbysql = (int) rm.get(0).get("iUserId");
			int iActivityIdbysql = (int) rm.get(0).get("iActivityId");

			// 判断写入的字段正确
			Logger.verifyEquals(activityId1, iActivityIdbysql, "sql对比直播id");
			Logger.verifyEquals(ProductID1, sProductIdbysql, "sql对比商品id");
			Logger.verifyEquals(sellerId, iUserIdbysql, "sql对比用户id");

			if (YmtMongoDriverFactroy.isOldMongoCheck()) {
				// Mongo 老库检查 LiveProductInfo & LiveBasicInfo
				addProductInLivesCall.checkLiveProductInfo(Live, Product, activityId1, ProductID1);
				addProductInLivesCall.checkLiveBasicInfo(Live, Product, activityId1);

			}

			if (YmtMongoDriverFactroy.isNewMongoCheck()) {
				// Mongo 新库检查 LiveProductModel & LiveModel
				addProductInLivesCall.checkLiveProductModel(Live, Product, activityId1, ProductID1);
				addProductInLivesCall.checkLiveModel(Live, Product, activityId1);
			}

			if (YmtMongoDriverFactroy.isNewJavaMgoCheck()) {
				Logger.verifyEquals(1, new LiveProductsWapper().getCountByProductId(ProductID1),
						"Mongo-LiveProducts 检查直播商品记录个数");
				NewJavaMongoCheckService.checkProductMgoSyncBySQL_NewJavaMgo(ProductID1);
			}

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_AttachProductToLives_004() {
		Logger.start(true, "现货加入直播后，再移出直播");
		try {
			// 1 创建直播
			JSONObject Live = LiveCallService.createLiveInProgress(sellerName, sellerId);
			Integer activityId1 = Live.getJSONObject("Data").getInt("ActivityId");

			// 2 发布商品
			Map<String, Object> map = new HashMap<String, Object>();

			// 销售状态 等于1 为 开始销售 销售状态等于0 为 未开始
			BigDecimal Price = new BigDecimal("100.00");
			BigDecimal VipPrice = new BigDecimal("10.00");
			BigDecimal NewCustomerPrice = new BigDecimal("10.00");
			String PictureUrl1 = "http://pc1.img.ymatou.com/G01/shangou/M00/2A/17/rBBlD1eqnq-AEvUHAANhqAY9_CQ839_n_w_o.jpg";
			map.put("Product->Catalogs[0]->Price", Price);
			map.put("Product->Catalogs[0]->VipPrice", VipPrice);
			map.put("Product->Catalogs[0]->NewCustomerPrice", NewCustomerPrice);
			map.put("Product->Catalogs[0]->PictureUrl1", PictureUrl1);
			JSONObject Product = SellerProductCallService.addNewProductOnSale(sellerId, sellerName, map);
			String ProductID1 = Product.getJSONObject("Data").getString("ProductID");

			// 直接加入商品 组装报文
			List<Integer> list = new ArrayList<>();
			list.add(activityId1);
			Map<String, Object> maplist = new HashMap<String, Object>();
			maplist.put("SellerId", sellerId);
			maplist.put("LiveIdList", new JSONArray(list));
			maplist.put("ProductId", ProductID1);

			// 3 call 加入直播接口
			JSONObject dataStr = attachproducttolivesCall.callAndGetReturnData(maplist);
			// 报文断言
			chackreturncode(dataStr);

			if (YmtMongoDriverFactroy.isNewJavaMgoCheck()) {
				Logger.verifyEquals(1, new LiveProductsWapper().getCountByProductId(ProductID1),
						"Mongo-LiveProducts 检查直播商品记录个数");
				NewJavaMongoCheckService.checkProductMgoSyncBySQL_NewJavaMgo(ProductID1);
			}

			// 4 remove product from live
			Map<String, Object> removeUpdateMap = new HashMap<String, Object>();
			removeUpdateMap.put("ProductId", ProductID1);
			removeUpdateMap.put("LiveId", activityId1);
			removeUpdateMap.put("UserId", sellerId);
			JSONObject removeProductBean = new RemoveProductFromLiveCall().callAndGetReturnData(removeUpdateMap);
			Logger.verifyEquals(200, removeProductBean.getInt("Code"), "响应报文-返回码");

			// check SQL YmtProductsInLiveWapper
			YmtProductsInLiveWapper ymtProductsInLiveWapper = new YmtProductsInLiveWapper();
			Logger.verifyEquals(1, ymtProductsInLiveWapper.selectByLiveId(activityId1).size(),
					"YmtProductsInLiveWapper 移出直播，记录清除");
			Logger.verifyEquals(-1, ymtProductsInLiveWapper.selectByLiveId(activityId1).get(0).getiAction(),
					"YmtProductsInLiveWapper iaction记录置为-1");

			// Check Mongo
			// ProductBasicInfo
			if (YmtMongoDriverFactroy.isOldMongoCheck()) {
				// 不维护
				// Map<String, Object> ProductBasicInfoMap = new
				// ProductBasicInfoWapper().getByProductId(productId);
				// Logger.verifyEquals(false,Boolean.parseBoolean(ProductBasicInfoMap.get("IsLiveProduct").toString()),
				// "Mongo-ProductBasicInfo IsLiveProduct");

				// LiveProductInfo
				Map<String, Object> liveProductInfoMap = new LiveProductInfoWapper()
						.getliveproductByProductId(ProductID1);
				Logger.verifyIsNull(liveProductInfoMap, "Mongo-LiveProductInfo");
			}

			if (YmtMongoDriverFactroy.isNewMongoCheck()) {
				// Mongo 新库检查 LiveProductModel & LiveModel
				LiveCallService.checkNewMongoLiveModel(Live, null, activityId1);
				Map<String, Object> liveProductModelMap = new LiveProductModelWapper().getActivityId(activityId1);
				Logger.verifyIsNull(liveProductModelMap, "Mongo-LiveProductModel");
			}

			if (YmtMongoDriverFactroy.isNewJavaMgoCheck()) {
				Logger.verifyEquals(0, new LiveProductsWapper().getCountByProductId(ProductID1),
						"Mongo-LiveProducts 检查直播商品记录个数");
				NewJavaMongoCheckService.checkProductMgoSyncBySQL_NewJavaMgo(ProductID1);
			}

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_AttachProductToLives_005() {
		Logger.start(true, "校验首次露出时间 - 直播进行中 - 商品定时上架");
		try {
			// 创建直播
			Integer activityId1 = LiveCallService.createLiveInProgress(sellerName, sellerId).getJSONObject("Data")
					.getInt("ActivityId");

			// 发布定时上架商品
			JSONObject Product = SellerProductCallService.addNewProductOnTime(sellerId, sellerName, null);
			String ProductID1 = Product.getJSONObject("Data").getString("ProductID");

			// 直接加入商品 组装报文
			List<Integer> list = new ArrayList<>();
			list.add(activityId1);
			Map<String, Object> maplist = new HashMap<String, Object>();
			maplist.put("SellerId", sellerId);
			maplist.put("LiveIdList", new JSONArray(list));
			maplist.put("ProductId", ProductID1);

			// call 加入直播接口
			JSONObject dataStr = attachproducttolivesCall.callAndGetReturnData(maplist);
			// 报文断言
			chackreturncode(dataStr);

			// 首次露出时间、结束时间断言
			SellerProductCallService.checkSqlListingTime(ProductID1, 1);
			SellerProductCallService.checkListingTime(ProductID1, null);

			if (YmtMongoDriverFactroy.isNewJavaMgoCheck()) {
				Logger.verifyEquals(1, new LiveProductsWapper().getCountByProductId(ProductID1),
						"Mongo-LiveProducts 检查直播商品记录个数");
				NewJavaMongoCheckService.checkProductMgoSyncBySQL_NewJavaMgo(ProductID1);
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_AttachProductToLives_006() {
		Logger.start(true, "校验首次露出时间 - 直播进行中 - 商品已上架");
		try {
			// 创建直播
			Integer activityId1 = LiveCallService.createLiveInProgress(sellerName, sellerId).getJSONObject("Data")
					.getInt("ActivityId");

			// 发布定时上架商品
			JSONObject Product = SellerProductCallService.addNewProductOnSale(sellerId, sellerName, null);
			String ProductID1 = Product.getJSONObject("Data").getString("ProductID");

			// 直接加入商品 组装报文
			List<Integer> list = new ArrayList<>();
			list.add(activityId1);
			Map<String, Object> maplist = new HashMap<String, Object>();
			maplist.put("SellerId", sellerId);
			maplist.put("LiveIdList", new JSONArray(list));
			maplist.put("ProductId", ProductID1);

			// call 加入直播接口
			JSONObject dataStr = attachproducttolivesCall.callAndGetReturnData(maplist);
			// 报文断言
			chackreturncode(dataStr);

			// 首次露出时间、结束时间断言
			SellerProductCallService.checkSqlListingTime(ProductID1, 1);
			SellerProductCallService.checkListingTime(ProductID1, null);

			if (YmtMongoDriverFactroy.isNewJavaMgoCheck()) {
				Logger.verifyEquals(1, new LiveProductsWapper().getCountByProductId(ProductID1),
						"Mongo-LiveProducts 检查直播商品记录个数");
				NewJavaMongoCheckService.checkProductMgoSyncBySQL_NewJavaMgo(ProductID1);
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_AttachProductToLives_007() {
		Logger.start(true, "校验首次露出时间 - 直播进行中 - 商品发布但上架");
		try {
			// 创建直播
			Integer activityId1 = LiveCallService.createLiveInProgress(sellerName, sellerId).getJSONObject("Data")
					.getInt("ActivityId");

			// 发布定时上架商品
			JSONObject Product = SellerProductCallService.addNewProductNotOnSale(sellerId, sellerName, null);
			String ProductID1 = Product.getJSONObject("Data").getString("ProductID");

			// 直接加入商品 组装报文
			List<Integer> list = new ArrayList<>();
			list.add(activityId1);
			Map<String, Object> maplist = new HashMap<String, Object>();
			maplist.put("SellerId", sellerId);
			maplist.put("LiveIdList", new JSONArray(list));
			maplist.put("ProductId", ProductID1);

			// call 加入直播接口
			JSONObject dataStr = attachproducttolivesCall.callAndGetReturnData(maplist);
			// 报文断言
			chackreturncode(dataStr);

			// 首次露出时间、结束时间断言
			SellerProductCallService.checkSqlListingTime(ProductID1, 1);
			SellerProductCallService.checkListingTime(ProductID1, null);

			if (YmtMongoDriverFactroy.isNewJavaMgoCheck()) {
				Logger.verifyEquals(1, new LiveProductsWapper().getCountByProductId(ProductID1),
						"Mongo-LiveProducts 检查直播商品记录个数");
				NewJavaMongoCheckService.checkProductMgoSyncBySQL_NewJavaMgo(ProductID1);
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_AttachProductToLives_008() {
		Logger.start(true, "校验首次露出时间 - 直播未开始 - 商品定时上架 - 直播开始在前");
		try {
			// 创建直播
			Integer activityId1 = LiveCallService.createLiveBeginInFuture(sellerName, sellerId).getJSONObject("Data")
					.getInt("ActivityId");

			// 发布定时上架商品
			JSONObject Product = SellerProductCallService.addNewProductOnTime(sellerId, sellerName, null);
			String ProductID1 = Product.getJSONObject("Data").getString("ProductID");

			// 直接加入商品 组装报文
			List<Integer> list = new ArrayList<>();
			list.add(activityId1);
			Map<String, Object> maplist = new HashMap<String, Object>();
			maplist.put("SellerId", sellerId);
			maplist.put("LiveIdList", new JSONArray(list));
			maplist.put("ProductId", ProductID1);

			// call 加入直播接口
			JSONObject dataStr = attachproducttolivesCall.callAndGetReturnData(maplist);
			// 报文断言
			chackreturncode(dataStr);

			// 首次露出时间、结束时间断言
			SellerProductCallService.checkSqlListingTime(ProductID1, 3);
			SellerProductCallService.checkListingTime(ProductID1, null);

			if (YmtMongoDriverFactroy.isNewJavaMgoCheck()) {
				Logger.verifyEquals(1, new LiveProductsWapper().getCountByProductId(ProductID1),
						"Mongo-LiveProducts 检查直播商品记录个数");
				NewJavaMongoCheckService.checkProductMgoSyncBySQL_NewJavaMgo(ProductID1);
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_AttachProductToLives_009() {
		Logger.start(true, "校验首次露出时间 - 直播未开始 - 商品定时上架 - 直播开始在后");
		try {
			// 创建直播
			Integer activityId1 = LiveCallService.createLiveBegin6dayInFuture(sellerName, sellerId)
					.getJSONObject("Data").getInt("ActivityId");

			// 发布定时上架商品
			JSONObject Product = SellerProductCallService.addNewProductOnTime(sellerId, sellerName, null);
			String ProductID1 = Product.getJSONObject("Data").getString("ProductID");

			// 直接加入商品 组装报文
			List<Integer> list = new ArrayList<>();
			list.add(activityId1);
			Map<String, Object> maplist = new HashMap<String, Object>();
			maplist.put("SellerId", sellerId);
			maplist.put("LiveIdList", new JSONArray(list));
			maplist.put("ProductId", ProductID1);

			// call 加入直播接口
			JSONObject dataStr = attachproducttolivesCall.callAndGetReturnData(maplist);
			// 报文断言
			chackreturncode(dataStr);

			// 首次露出时间、结束时间断言
			SellerProductCallService.checkSqlListingTime(ProductID1, 2);
			SellerProductCallService.checkListingTime(ProductID1, null);

			if (YmtMongoDriverFactroy.isNewJavaMgoCheck()) {
				Logger.verifyEquals(1, new LiveProductsWapper().getCountByProductId(ProductID1),
						"Mongo-LiveProducts 检查直播商品记录个数");
				NewJavaMongoCheckService.checkProductMgoSyncBySQL_NewJavaMgo(ProductID1);
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_AttachProductToLives_010() {
		Logger.start(true, "校验首次露出时间 - 直播未开始 - 商品已上架");
		try {
			// 创建直播
			Integer activityId1 = LiveCallService.createLiveBeginInFuture(sellerName, sellerId).getJSONObject("Data")
					.getInt("ActivityId");

			// 发布定时上架商品
			JSONObject Product = SellerProductCallService.addNewProductOnSale(sellerId, sellerName, null);
			String ProductID1 = Product.getJSONObject("Data").getString("ProductID");

			// 直接加入商品 组装报文
			List<Integer> list = new ArrayList<>();
			list.add(activityId1);
			Map<String, Object> maplist = new HashMap<String, Object>();
			maplist.put("SellerId", sellerId);
			maplist.put("LiveIdList", new JSONArray(list));
			maplist.put("ProductId", ProductID1);

			// call 加入直播接口
			JSONObject dataStr = attachproducttolivesCall.callAndGetReturnData(maplist);
			// 报文断言
			chackreturncode(dataStr);

			// 首次露出时间、结束时间断言
			SellerProductCallService.checkSqlListingTime(ProductID1, 1);
			SellerProductCallService.checkListingTime(ProductID1, null);

			if (YmtMongoDriverFactroy.isNewJavaMgoCheck()) {
				Logger.verifyEquals(1, new LiveProductsWapper().getCountByProductId(ProductID1),
						"Mongo-LiveProducts 检查直播商品记录个数");
				NewJavaMongoCheckService.checkProductMgoSyncBySQL_NewJavaMgo(ProductID1);
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_AttachProductToLives_011() {
		Logger.start(true, "校验首次露出时间 - 直播未开始 - 商品发布但上架");
		try {
			// 创建直播
			Integer activityId1 = LiveCallService.createLiveBeginInFuture(sellerName, sellerId).getJSONObject("Data")
					.getInt("ActivityId");

			// 发布定时上架商品
			JSONObject Product = SellerProductCallService.addNewProductNotOnSale(sellerId, sellerName, null);
			String ProductID1 = Product.getJSONObject("Data").getString("ProductID");

			// 直接加入商品 组装报文
			List<Integer> list = new ArrayList<>();
			list.add(activityId1);
			Map<String, Object> maplist = new HashMap<String, Object>();
			maplist.put("SellerId", sellerId);
			maplist.put("LiveIdList", new JSONArray(list));
			maplist.put("ProductId", ProductID1);

			// call 加入直播接口
			JSONObject dataStr = attachproducttolivesCall.callAndGetReturnData(maplist);
			// 报文断言
			chackreturncode(dataStr);

			// 首次露出时间、结束时间断言
			SellerProductCallService.checkSqlListingTime(ProductID1, 3);
			SellerProductCallService.checkListingTime(ProductID1, null);

			if (YmtMongoDriverFactroy.isNewJavaMgoCheck()) {
				Logger.verifyEquals(1, new LiveProductsWapper().getCountByProductId(ProductID1),
						"Mongo-LiveProducts 检查直播商品记录个数");
				NewJavaMongoCheckService.checkProductMgoSyncBySQL_NewJavaMgo(ProductID1);
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_AttachProductToLives_012() {
		Logger.start(true, "校验首次露出时间 - 直播未开始 - 商品定时上架 - 再移除直播");
		try {
			// 创建直播
			Integer activityId1 = LiveCallService.createLiveBeginInFuture(sellerName, sellerId).getJSONObject("Data")
					.getInt("ActivityId");

			// 发布定时上架商品
			JSONObject Product = SellerProductCallService.addNewProductOnTime(sellerId, sellerName, null);
			String ProductID1 = Product.getJSONObject("Data").getString("ProductID");

			// 直接加入商品 组装报文
			List<Integer> list = new ArrayList<>();
			list.add(activityId1);
			Map<String, Object> maplist = new HashMap<String, Object>();
			maplist.put("SellerId", sellerId);
			maplist.put("LiveIdList", new JSONArray(list));
			maplist.put("ProductId", ProductID1);

			YMTDateUtil.waitTime(1);

			// call 加入直播接口
			JSONObject dataStr = attachproducttolivesCall.callAndGetReturnData(maplist);
			if (YmtMongoDriverFactroy.isNewJavaMgoCheck()) {
				Logger.verifyEquals(1, new LiveProductsWapper().getCountByProductId(ProductID1),
						"Mongo-LiveProducts 检查直播商品记录个数");
				NewJavaMongoCheckService.checkProductMgoSyncBySQL_NewJavaMgo(ProductID1);
			}
			YMTDateUtil.waitTime(2);

			// 移除直播
			Map<String, Object> removeUpdateMap = new HashMap<String, Object>();
			removeUpdateMap.put("ProductId", ProductID1);
			removeUpdateMap.put("LiveId", activityId1);
			removeUpdateMap.put("UserId", sellerId);
			JSONObject removeProductBean = new RemoveProductFromLiveCall().callAndGetReturnData(removeUpdateMap);
			Logger.verifyEquals(200, removeProductBean.getInt("Code"), "响应报文-返回码");

			// 首次露出时间、结束时间断言
			SellerProductCallService.checkSqlListingTime(ProductID1, 2);
			SellerProductCallService.checkListingTime(ProductID1, null);

			if (YmtMongoDriverFactroy.isNewJavaMgoCheck()) {
				Logger.verifyEquals(0, new LiveProductsWapper().getCountByProductId(ProductID1),
						"Mongo-LiveProducts 检查直播商品记录个数");
				NewJavaMongoCheckService.checkProductMgoSyncBySQL_NewJavaMgo(ProductID1);
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_AttachProductToLives_013() {
		Logger.start(true, "校验首次露出时间 - 首次lisitngtime已过，加入直播后不改变");
		try {
			// 创建直播
			Integer activityId1 = LiveCallService.createLiveBeginInFuture(sellerName, sellerId).getJSONObject("Data")
					.getInt("ActivityId");

			// 发布上架商品
			JSONObject Product = SellerProductCallService.addNewProductOnSale(sellerId, sellerName, null);
			String ProductID1 = Product.getJSONObject("Data").getString("ProductID");

			// 直接加入商品 组装报文
			List<Integer> list = new ArrayList<>();
			list.add(activityId1);
			Map<String, Object> maplist = new HashMap<String, Object>();
			maplist.put("SellerId", sellerId);
			maplist.put("LiveIdList", new JSONArray(list));
			maplist.put("ProductId", ProductID1);

			YMTDateUtil.waitTime(1);

			// call 加入直播接口
			JSONObject dataStr = attachproducttolivesCall.callAndGetReturnData(maplist);

			YMTDateUtil.waitTime(2);

			YMTDateUtil.waitTime(3);

			// 首次露出时间、结束时间断言
			SellerProductCallService.checkSqlListingTime(ProductID1, 2);
			SellerProductCallService.checkListingTime(ProductID1, null);

			if (YmtMongoDriverFactroy.isNewJavaMgoCheck()) {
				Logger.verifyEquals(1, new LiveProductsWapper().getCountByProductId(ProductID1),
						"Mongo-LiveProducts 检查直播商品记录个数");
				NewJavaMongoCheckService.checkProductMgoSyncBySQL_NewJavaMgo(ProductID1);
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_AttachProductToLives_014() {
		Logger.start(true, "校验首次露出时间 - 上架时间<直播A<直播B，listingtime为上架时间");
		try {
			// 创建6天后的直播A
			Integer activityId1 = LiveCallService.createLiveBegin6dayInFuture(sellerName, sellerId)
					.getJSONObject("Data").getInt("ActivityId");
			// 创建8天后的直播
			Calendar c = Calendar.getInstance();
			Map<String, Object> updateMap = new HashMap<String, Object>();

			updateMap.put("ActivityRequest->SellerName", sellerName);
			updateMap.put("ActivityRequest->UserId", sellerId);
			updateMap.put("ActivityRequest->AppConfirmed", 1);
			updateMap.put("ActivityRequest->ActivityName", "自动化_即将开始直播");

			c.add(Calendar.DAY_OF_MONTH, 8);
			updateMap.put("ActivityRequest->StartTime", liveSDF.format(c.getTime()));
			c.add(Calendar.HOUR, 2);
			updateMap.put("ActivityRequest->EndTime", liveSDF.format(c.getTime()));

			Integer activityid2 = new CreateLiveCall().callAndGetReturnData(updateMap).getJSONObject("Data")
					.getInt("ActivityId");

			// 发布5天后上架商品

			JSONObject Product = SellerProductCallService.addNewProductOnTime(sellerId, sellerName, null);
			String ProductID1 = Product.getJSONObject("Data").getString("ProductID");

			YMTDateUtil.waitTime(1);
			List<Integer> list = new ArrayList<>();
			list.add(activityId1);
			list.add(activityid2);
			Map<String, Object> maplist = new HashMap<String, Object>();
			maplist.put("SellerId", sellerId);
			maplist.put("LiveIdList", new JSONArray(list));
			maplist.put("ProductId", ProductID1);

			// call 加入直播接口
			JSONObject dataStr = attachproducttolivesCall.callAndGetReturnData(maplist);

			YMTDateUtil.waitTime(2);

			YMTDateUtil.waitTime(3);

			// 首次露出时间、结束时间断言
			SellerProductCallService.checkSqlListingTime(ProductID1, 2);
			SellerProductCallService.checkListingTime(ProductID1, null);

			if (YmtMongoDriverFactroy.isNewJavaMgoCheck()) {
				Logger.verifyEquals(2, new LiveProductsWapper().getCountByProductId(ProductID1),
						"Mongo-LiveProducts 检查直播商品记录个数");
				NewJavaMongoCheckService.checkProductMgoSyncBySQL_NewJavaMgo(ProductID1);
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_AttachProductToLives_015() {
		Logger.start(true, "校验首次露出时间 - 直播A<直播B<上架时间<，listingtime为直播A");
		try {
			// 创建6天后的直播A
			Integer activityId1 = LiveCallService.createLiveBegin6dayInFuture(sellerName, sellerId)
					.getJSONObject("Data").getInt("ActivityId");
			// 创建8天后的直播
			Calendar c = Calendar.getInstance();
			Map<String, Object> updateMap = new HashMap<String, Object>();

			updateMap.put("ActivityRequest->SellerName", sellerName);
			updateMap.put("ActivityRequest->UserId", sellerId);
			updateMap.put("ActivityRequest->AppConfirmed", 1);
			updateMap.put("ActivityRequest->ActivityName", "自动化_即将开始直播");

			c.add(Calendar.DAY_OF_MONTH, 8);
			updateMap.put("ActivityRequest->StartTime", liveSDF.format(c.getTime()));
			c.add(Calendar.HOUR, 2);
			updateMap.put("ActivityRequest->EndTime", liveSDF.format(c.getTime()));

			Integer activityid2 = new CreateLiveCall().callAndGetReturnData(updateMap).getJSONObject("Data")
					.getInt("ActivityId");

			// 发布10天后上架商品
			Map<String, Object> updatemap1 = new HashMap<String, Object>();
			Calendar d = Calendar.getInstance();
			d.add(Calendar.DAY_OF_MONTH, 10);
			updatemap1.put("Product->ValidStart", sdf.format(d.getTime()));

			d.add(Calendar.DAY_OF_MONTH, 17);
			updatemap1.put("Product->ValidEnd", sdf.format(d.getTime()));
			JSONObject Product = SellerProductCallService.addNewProductOnTime(sellerId, sellerName, updatemap1);
			String ProductID1 = Product.getJSONObject("Data").getString("ProductID");

			YMTDateUtil.waitTime(1);
			List<Integer> list = new ArrayList<>();
			list.add(activityId1);
			list.add(activityid2);
			Map<String, Object> maplist = new HashMap<String, Object>();
			maplist.put("SellerId", sellerId);
			maplist.put("LiveIdList", new JSONArray(list));
			maplist.put("ProductId", ProductID1);

			// call 加入直播接口
			JSONObject dataStr = attachproducttolivesCall.callAndGetReturnData(maplist);

			YMTDateUtil.waitTime(2);

			YMTDateUtil.waitTime(3);

			// 首次露出时间、结束时间断言
			SellerProductCallService.checkSqlListingTime(ProductID1, 3);
			SellerProductCallService.checkListingTime(ProductID1, null);

			if (YmtMongoDriverFactroy.isNewJavaMgoCheck()) {
				Logger.verifyEquals(2, new LiveProductsWapper().getCountByProductId(ProductID1),
						"Mongo-LiveProducts 检查直播商品记录个数");
				NewJavaMongoCheckService.checkProductMgoSyncBySQL_NewJavaMgo(ProductID1);
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_AttachProductToLives_016() {
		Logger.start(true, "校验首次露出时间 - listing时间未过，加入正在进行中的直播，lisitngtime为加入直播的时间");
		try {

			// 创建正在进行中的直播
			Integer activityid = LiveCallService.createLiveInProgress(sellerName, sellerId).getJSONObject("Data")
					.getInt("ActivityId");
			// 发布一个不上架的商品
			String productid = SellerProductCallService.addNewProductNotOnSale(sellerId, sellerName, null)
					.getJSONObject("Data").getString("ProductID");

			// 修改接口参数
			List list = new ArrayList<>();
			list.add(activityid);
			Map<String, Object> updatemap = new HashMap<String, Object>();
			updatemap.put("SellerId", sellerId);
			updatemap.put("LiveIdList", new JSONArray(list));
			updatemap.put("ProductId", productid);
			// 组装修改后的参数并call接口
			JSONObject response = attachproducttolivesCall.callAndGetReturnData(updatemap);
			Logger.verifyEquals(200, response.getInt("Code"), "接口返回200");
			JSONObject request = response.getJSONObject(JsonBeanHelper.JsonBeanRequest);
			// 验证listingtime时间
			SellerProductCallService.checkSqlListingTime(productid, 1);
			SellerProductCallService.checkListingTime(productid, null);

			if (YmtMongoDriverFactroy.isNewJavaMgoCheck()) {
				Logger.verifyEquals(1, new LiveProductsWapper().getCountByProductId(productid),
						"Mongo-LiveProducts 检查直播商品记录个数");
				NewJavaMongoCheckService.checkProductMgoSyncBySQL_NewJavaMgo(productid);
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_AttachProductToLives_017() {
		Logger.start(true, "现货加入直播 修改商品 检查mongo时间戳变化");
		try {
			
			if (YmtMongoDriverFactroy.isNewJavaMgoCheck()){
				ProductTimeStampBean productTimeStampBean = new ProductTimeStampBean();
				ProductTimeStampWapper productTimeStampWapper = new ProductTimeStampWapper();
				
				//1.添加商品 -不上架
				
				JSONObject productReqObject = SellerProductCallService.addNewProductNotOnSale(sellerId, sellerName, null);
				String productId =  productReqObject.getJSONObject("Data").getString("ProductID");
				productTimeStampBean.setProductId(productId);
				
				//check time 
				Map<String, Object> dateInMgo = productTimeStampWapper.getByProductId(productId);
				
				productTimeStampBean.setCut((Date)dateInMgo.get("cut"));
				productTimeStampBean.setSut((Date)dateInMgo.get("sut"));
				Logger.verifyIsNull(dateInMgo.get("aut"),"ProductTimeStamp aut 应该没有");
				Logger.verifyIsNull(dateInMgo.get("lut"),"ProductTimeStamp lut 应该没有");
				
				
				
				
				//2 商品加入直播
				JSONObject liveResponseBean = LiveCallService.createLiveInProgress(sellerName, sellerId);
				int liveId =  liveResponseBean.getJSONObject("Data").getInt("ActivityId");
				SellerProductCallService.addProductInLive(sellerId, liveId, productId);
			
				//check time
				YMTDateUtil.waitTime(5);
				dateInMgo = productTimeStampWapper.getByProductId(productId);
				Logger.verifyEquals(true,productTimeStampBean.getCut().before((Date)dateInMgo.get("cut")),"ProductTimeStamp cut应该变化");
				Logger.verifyEquals(true,productTimeStampBean.getSut().before((Date)dateInMgo.get("sut")),"ProductTimeStamp sut应该变化");
				
				productTimeStampBean.setCut((Date)dateInMgo.get("cut"));
				productTimeStampBean.setSut((Date)dateInMgo.get("sut"));
				productTimeStampBean.setLut((Date)dateInMgo.get("lut"));
				Logger.verifyIsNull(dateInMgo.get("aut"),"ProductTimeStamp aut 应该没有");
				
				
				
				
				//修改商品
				String catalogsId = new YmtCatalogsIWapper().selectCatalogsByProductId(productId).get(0).getsCatalogId();
				Map<String, Object> updateMap = MapUtil.hashMap("LoginID", sellerName, "UserID", sellerId,
						"Product->sProductId",productId,"ProductID",productId,
						"Product->OnSaleType",0,"Product->Catalogs[2]->CatalogId",catalogsId);
		
				String fileName = "changenewproductinfocalltpl_001.json";
				JSONObject responseBean = new ChangeNewProductInfoCall().callAndGetReturnData(fileName,updateMap);
				Logger.verifyEquals(200, responseBean.getInt("Code"), "响应报文-返回码");
				
				//check time
				
				YMTDateUtil.waitTime(5);
				dateInMgo = productTimeStampWapper.getByProductId(productId);
				Logger.verifyEquals(true,productTimeStampBean.getCut().before((Date)dateInMgo.get("cut")),"ProductTimeStamp cut应该变化");
				Logger.verifyEquals(true,productTimeStampBean.getSut().before((Date)dateInMgo.get("sut")),"ProductTimeStamp sut应该变化");
				Logger.verifyEquals(true,productTimeStampBean.getLut().equals((Date)dateInMgo.get("lut")),"ProductTimeStamp lut应该没有变化");
					
				//update time
				productTimeStampBean.setCut((Date)dateInMgo.get("cut"));
				productTimeStampBean.setSut((Date)dateInMgo.get("sut"));
				productTimeStampBean.setLut((Date)dateInMgo.get("lut"));
				Logger.verifyIsNull(dateInMgo.get("aut"),"ProductTimeStamp aut 应该没有");
				
				
				
				//修改直播
				String Title = "自动化测试 - 直播名称1";
				String ActivityName = "自动化测试  - 直播地名称1";
				String PicUrl = "http://pc1.img.ymatou.com/G01/M00/0A/C9/rBBlD1b0p-2AF1waAAAGdC5-fgw197_c1.jpg";
				String ActivityContent = "自动化测试 - 直播介绍1";
	
				Map<String, Object> updateMapLive = new HashMap<String, Object>();
				updateMapLive.put("Activity->Title", Title);
				updateMapLive.put("Activity->ActivityName", ActivityName);
				updateMapLive.put("Activity->ActivityContent", ActivityContent);
				updateMapLive.put("Activity->PicUrl", PicUrl);
				updateMapLive.put("Activity->VideoAction", 1);
	
				LiveCallService.saveLive(sellerName, sellerId, liveId,updateMapLive);
				
				
				YMTDateUtil.waitTime(5);
				dateInMgo = productTimeStampWapper.getByProductId(productId);
				Logger.verifyEquals(true,productTimeStampBean.getCut().equals((Date)dateInMgo.get("cut")),"ProductTimeStamp cut应该没有变化");
	
				Logger.verifyEquals(true,productTimeStampBean.getSut().before((Date)dateInMgo.get("sut")),"ProductTimeStamp sut应该变化");
				Logger.verifyEquals(true,productTimeStampBean.getLut().before((Date)dateInMgo.get("lut")),"ProductTimeStamp lut应该变化");
					
				productTimeStampBean.setCut((Date)dateInMgo.get("cut"));
				productTimeStampBean.setSut((Date)dateInMgo.get("sut"));
				productTimeStampBean.setLut((Date)dateInMgo.get("lut"));
				Logger.verifyIsNull(dateInMgo.get("aut"),"ProductTimeStamp aut 应该没有");	
				
			/*	
				//参加活动
				ProductPriceCallService.getProdPriceWithActivity(sellerId,productId,MapUtil.hashMap("ActivityTemplateId", 19));
	
				YMTDateUtil.waitTime(5);
				dateInMgo = productTimeStampWapper.getByProductId(productId);
				Logger.verifyEquals(true,productTimeStampBean.getCut().equals((Date)dateInMgo.get("cut")),"ProductTimeStamp cut应该没有变化");
				Logger.verifyEquals(true,productTimeStampBean.getLut().equals((Date)dateInMgo.get("lut")),"ProductTimeStamp lut应该没有变化");
				Logger.verifyEquals(true,productTimeStampBean.getSut().before((Date)dateInMgo.get("sut")),"ProductTimeStamp sut应该变化");
	
					
				Date currentDate = YMTDateUtil.getDate();
				AssertService.assertTime(currentDate, (Date) dateInMgo.get("aut"), 300,"Mongo-ProductTimeStamp aut");*/
					
				
			}
			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	

}